<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div class="fixed-table-pagination" style="display: block;">
	<c:if test="${page.total < 1 }">
		抱歉，查询不到任何相关的记录。
	</c:if>
	<c:if test="${page.total > 0 }">
		<div class="pull-left pagination-detail">
			<span class="pagination-info">共 ${page.pages } 页 ${page.total } 条记录</span> 
			<span class="page-list">每页显示 
				<span class="btn-group dropup">
					<button type="button" class="btn btn-default  btn-outline dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
						<span>${page.pageSize }</span> 
						<span class="caret"></span>
					</button>
					<ul class="dropdown-menu" role="menu">
						<li class="active"><a href="javascript:SetPage(10);">10</a></li>
						<li class=""><a href="javascript:SetPage(25);">25</a></li>
						<li class=""><a href="javascript:SetPage(50);">50</a></li>
						<li class=""><a href="javascript:SetPage(100);">100</a></li>
					</ul>
				</span> 条记录
			</span>
		</div>
		<div class="pull-right pagination-roll">
		<ul class="pagination pagination-outline">
			<li class="paginate_button previous ${page.pageNum == 1 ? 'disabled' : '' }">
				<c:choose>
					<c:when test="${page.pageNum > 1 }">
						<a href="javascript:JumpPage(1);"><i class="fa fa-angle-double-left"></i></a>
					</c:when>
					<c:otherwise>
						<a href="javascript:void();"><i class="fa fa-angle-double-left"></i></a>
					</c:otherwise>
				</c:choose>
			</li>
			<li class="paginate_button previous ${(page.prePage < page.navigateFirstPage) ? 'disabled' : '' }">
				<c:choose>
					<c:when test="${page.pageNum > 1 }">
						<a href="javascript:JumpPage(${page.prePage });"><i class="fa fa-angle-left"></i></a>
					</c:when>
					<c:otherwise>
						<a href="javascript:void();"><i class="fa fa-angle-left"></i></a>
					</c:otherwise>
				</c:choose>
			</li>
			<c:forEach var="pageNum" items="${page.navigatepageNums }">
				<li class="paginate_button ${(pageNum == page.pageNum) ? "active" : "" }">
					<c:choose>
						<c:when test="${pageNum == page.pageNum }">
							<a href="javascript:void();"><c:out value="${pageNum }" /></a>
						</c:when>
						<c:otherwise>
							<a href="javascript:JumpPage(${pageNum });"><c:out value="${pageNum }" /></a>
						</c:otherwise>
					</c:choose>
				</li>
			</c:forEach>
			<!-- <li class="paginate_button active"><a href="javascript:">1</a></li> -->
			<li class="paginate_button next ${(page.nextPage > page.navigateLastPage || page.nextPage == 0) ? 'disabled' : '' }">
				<c:choose>
					<c:when test="${page.pageNum < page.pages }">
						<a href="javascript:JumpPage(${page.nextPage });"><i class="fa fa-angle-right"></i></a>
					</c:when>
					<c:otherwise>
						<a href="javascript:void();"><i class="fa fa-angle-right"></i></a>
					</c:otherwise>
				</c:choose>
			</li>
			<li class="paginate_button next ${(page.pageNum >= page.pages) ? 'disabled' : '' }">
				<c:choose>
					<c:when test="${page.pageNum < page.pages }">
						<a href="javascript:JumpPage(${page.pages });"><i class="fa fa-angle-double-right"></i></a>
					</c:when>
					<c:otherwise>
						<a href="javascript:void();"><i class="fa fa-angle-double-right"></i></a>
					</c:otherwise>
				</c:choose>
			</li>
		</ul>
	</div>
	</c:if>
</div>
<script type="text/javascript">
	$("#s_page_size").html("10");
	// 获取地址栏参数值
	function GetQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null)
			return unescape(r[2]);
		return null;
	}

	// 修改url参数
	function ChangeURLParam(par, par_value) {
		var destiny = window.location.href;
		var pattern = par + '=([^&]*)';
		var replaceText = par + '=' + par_value;
		if (destiny.match(pattern)) {
			var tmp = '/\\' + par + '=[^&]*/';
			tmp = destiny.replace(eval(tmp), replaceText);
			return (tmp);
		} else {
			if (destiny.match('[\?]')) {
				return destiny + '&' + replaceText;
			} else {
				return destiny + '?' + replaceText;
			}
		}
		return destiny + '\n' + par + '\n' + par_value;
	}
	
	// 翻页
	function JumpPage(page) {
		$("#pageNum").val(page);
		Search();
	}
	
	// 设置页大小
	function SetPage(pageSize) {
		//window.location.href = ChangeURLParam('pageSize', pageSize);
		$("#pageSize").val(pageSize);
		$("#pageVary").val(1);
		Search();
	}
	
	function initPage() {
		var pageSize = "${pageSize}";
		$(".dropdown-menu").each(function() {
			$(".page-size").text(pageSize);
			if ($(this).attr('role') == "menu") {
				$(this).find('li').each(function() {
					$(this).removeClass('active');
					if (parseInt($(this).text()) == parseInt(pageSize)) {
						$(this).addClass('active');
					}
				});
			}
		});
	}

	initPage();
	
	// 全选
	function SelectAll(obj) {
		$('input:checkbox').each(function() {
			$(this).prop('checked', obj.checked);
		});
	}
	
	// 查询
	function Search() {
		$('#SearchForm').submit();
	}
	
	// 刷新
	function Refresh() {
		window.location.reload();
	}
	
	// 编辑
	function Edit(url, title) {
		/* layer.open({
			type: 2,
			title: title,
			maxmin: true,
			area: ['700px', '800px'],
			content: url
		}); */
		window.location = url;
	}
	
	// 重置
	function Reset() {
		$('input:text').each(function() {
			$(this).val("");
		});
		$('input:hidden').each(function() {
			$(this).val("");
		});
		$('select').each(function() {
			$(this).val("");
		});
		Search();
	}

	// 删除选中
	function DelSel(page) {
		var idArray = "";
		if (page == null || page == undefined || page == '') {
			return;
		}
		$('input[name="sn"]:checked').each(function() {
			idArray += idArray == "" ? $(this).val() : "," + $(this).val();
		});
		Del(page, idArray);
	}

	// 删除
	function Del(page, id) {
		if (id == null || id == undefined || id == '') {
			layer.msg("请先勾选需要删除的记录.", {icon: 5});
			return;
		}
		if (page == null || page == undefined || page == '') {
			layer.msg("Page不能为空.", {icon: 5});
			return;
		}

		layer.confirm('确定要删除当前或选中数据吗？', {
			icon : 3,
			title : "删除提示",
			btn : [ "确定", "取消" ]
		//按钮
		}, function() {
			$.ajax({
				cache : true,
				type : "POST",
				url : page,
				data : "id=" + id,
				async : false,
				error : function(request) {
					layer.msg("Page不能为空.", {icon: 5});
				},
				success : function(data) {
					if (data == "Succ") {
						layer.msg('恭喜,删除订单成功.', {icon: 6});
						Search();
					} else {
						layer.msg('抱歉,删除订单失败.', {icon: 5});
					}
				}
			});
		}, function() {
			return;
		});
	}
</script>